/**
 * 报名信息管理初始化
 */
var Registration = {
    id: "RegistrationTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Registration.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'ID', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: '地址', field: 'address', visible: true, align: 'center', valign: 'middle'},
            {title: '单位', field: 'org', visible: true, align: 'center', valign: 'middle'},
            {title: '电话', field: 'tel', visible: true, align: 'center', valign: 'middle'},
            {title: '邮箱', field: 'email', visible: true, align: 'center', valign: 'middle'},
            {title: '人数', field: 'num', visible: true, align: 'center', valign: 'middle'},
            {title: '学生人数', field: 'student', visible: true, align: 'center', valign: 'middle'},
            {title: '邮编', field: 'postcode', visible: true, align: 'center', valign: 'middle'},
            {title: '会议酒店行政套房', field: 'room1', visible: false, align: 'center', valign: 'middle'},
            {title: '会议酒店普通套房', field: 'room2', visible: false, align: 'center', valign: 'middle'},
            {title: '会议酒店行政大床', field: 'room3', visible: false, align: 'center', valign: 'middle'},
            {title: '会议酒店行政双床', field: 'room4', visible: false, align: 'center', valign: 'middle'},
            {title: '会议酒店高级大床', field: 'room5', visible: false, align: 'center', valign: 'middle'},
            {title: '会议酒店高级双床', field: 'room6', visible: false, align: 'center', valign: 'middle'},
            {title: '会议酒店高级双床床位', field: 'room7', visible: false, align: 'center', valign: 'middle'},
            {title: '栖涧里创想酒店大床', field: 'room8', visible: false, align: 'center', valign: 'middle'},
            {title: '栖涧里创想酒店双床', field: 'room9', visible: false, align: 'center', valign: 'middle'},
            {title: '栖涧里创想酒店双床床位', field: 'room10', visible: false, align: 'center', valign: 'middle'},
            {title: '开票单位', field: 'taxname', visible: true, align: 'center', valign: 'middle'},
            {title: '纳税人识别号', field: 'taxcode', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'ext', visible: true, align: 'center', valign: 'middle'},
            {title: '状态', field: 'state', visible: true, align: 'center', valign: 'middle'},
            {title: '金额', field: 'price', visible: true, align: 'center', valign: 'middle'},
            {title: '已付款金额', field: 'paidPrice', visible: true, align: 'center', valign: 'middle'},
    ];
};

/**
 * 检查是否选中
 */
Registration.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Registration.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加报名信息
 */
Registration.openAddRegistration = function () {
    var index = layer.open({
        type: 2,
        title: '添加报名信息',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/registration/registration_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看报名信息详情
 */
Registration.openRegistrationDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '报名信息详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/registration/registration_update/' + Registration.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除报名信息
 */
Registration.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/registration/delete", function (data) {
            Feng.success("删除成功!");
            Registration.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("registrationId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 参会人员信息
 */
Registration.person = function () {
    if (this.check()) {
        Feng.newCrontab(Feng.ctxPath + '/person?condition=' + Registration.seItem.id,Registration.seItem.name+"参会人员");
    }
};

/**
 * 查询报名信息列表
 */
Registration.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Registration.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Registration.initColumn();
    var table = new BSTable(Registration.id, "/registration/list", defaultColunms);
    table.setPaginationType("client");
    Registration.table = table.init();
});
